package com.ansion.basedb.database.sql;

public class SQLUnionIndex {
    private int versionCode = 1;
    private final String[] columnNames;
    private final String tableName;

    public SQLUnionIndex(String tableName, String ... columns) {
        this.tableName = tableName;
        this.columnNames = columns;
    }

    public SQLUnionIndex setVersionCode(int versionCode) {
        this.versionCode = versionCode;
        return this;
    }


    public String buildIndexSQL() {
        StringBuilder sb = new StringBuilder();
        sb.append("CREATE INDEX IF NOT EXISTS ");
        sb.append("index");
        for (String columnName : columnNames) {
            sb.append("_");
            sb.append(columnName);
        }
        sb.append("_");
        sb.append(tableName);
        sb.append(" ON ");
        sb.append(tableName);
        sb.append(" (");
        for (String columnName : columnNames) {
            sb.append(columnName);
            sb.append(",");
        }
        sb.deleteCharAt(sb.length() - 1);
        sb.append(");");
        return sb.toString();
    }

    public int getVersionCode() {
        return versionCode;
    }
}
